import request from '@/utils/request'
/**
 * 获取文章详情
 * @param {*} id
 * @returns
 */
export function getArticleDetail(id) {
  return request({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}
/**
 * 关注用户
 * @param {*} id
 * @returns
 */
export function followUser(id) {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}

/**
 * 取消关注用户
 * @param {*} id
 * @returns
 */
export function unfollowUser(id) {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return request({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return request({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
/**
 * 获取评论
 * @param {*} articleId 文章的id
 * @param {*} offset 上一次返回的id， 如果是第一页，可以为null
 * @returns
 */
export function getCommentList(articleId, offset) {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset: offset
    }
  })
}
/**
 * 发表文章的评论
 * @param {*} articleId
 * @param {*} content
 * @returns
 */
export function addComment(articleId, content) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}
/**
 * 评论点赞
 * @param {*} id
 * @returns
 */
export function commentLike(id) {
  return request({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: id
    }
  })
}
/**
 * 取消点赞
 * @param {*} commentId
 * @returns
 */
export function deleteCommentLike(commentId) {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + commentId
  })
}

export function getCommentReply(commentId, offset) {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source: commentId,
      offset
    }
  })
}

/**
 * 添加回复接口
 * @param {*} commentId
 * @param {*} content
 * @param {*} articleId
 * @returns
 */
export function addReply(commentId, content, articleId) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content,
      art_id: articleId
    }
  })
}
